#include "Exception.hpp"
#include "Logger.hpp"
#include <Windows.h>

namespace ge {

//----------------------------------------------------------------------------//
// Exception
//----------------------------------------------------------------------------//

//----------------------------------------------------------------------------//
bool Exception::Report( void ) const
{
     String _msg = "Exception:\n\n    ";
     _msg += type + "\n    ";
     _msg += message + "\n    ";
     if( source.file.NonEmpty() )
     {
          _msg += source.file + String::Format( "(%d", source.row );
          if( source.col > 0 ) _msg += String::Format( ",%d", source.col );
          _msg += ")";
          if( source.func.NonEmpty() ) _msg += " : ";
     }
     if( source.func.NonEmpty() ) _msg += source.func;
     _msg += "\n\nSee log for more details.\n";
     
     if( Logger::HasInstance() ) Logger::Exception( *this );

     int _result = MessageBoxA( 0, _msg, "Exception", MB_ABORTRETRYIGNORE	| MB_ICONERROR | MB_DEFBUTTON1	| MB_APPLMODAL | MB_SETFOREGROUND | MB_TOPMOST );
     if( _result == IDABORT	)
     {
          if( Logger::HasInstance() ) Logger::Info( "Crash of application ..." );
          exit( -1 );
     } 
     return _result == IDRETRY;
}
//----------------------------------------------------------------------------//

//----------------------------------------------------------------------------//
//
//----------------------------------------------------------------------------//

} // namespace ge
